Template HaskellのAST
Literal
code:hs
data Lit = CharL Char
| StringL String
| IntegerL Integer
| RationalL Rational
| IntPrimL Integer
| WordPrimL Integer
| FloatPrimL Rational
| DoublePrimL Rational
| BytesPrimL Bytes
| CharPrimL Char
Exp
コメントアウトは多少省略してる
code:hs
data Exp
= VarE Name -- 変数
| ConE Name -- ^ @data T1 = C1 t1 t2; p = {C1} e1 e2 @
| LitE Lit -- Literal
| AppE Exp Exp -- 関数適用
| AppTypeE Exp Type -- ^ @{ f \@Int }@
| InfixE (Maybe Exp) Exp (Maybe Exp) -- ^ @{x + y} or {(x+)} or {(+ x)} or {(+)}@
| UInfixE Exp Exp Exp -- ^ @{x + y}@
| ParensE Exp -- 丸括弧
| LamE Pat Exp -- ^ @{ \\ p1 p2 -> e }@ | LamCaseE Match -- ^ @{ \\case m1; m2 }@ | UnboxedTupE Maybe Exp -- ^ @{ (\# e1,e2 \#) } @ | UnboxedSumE Exp SumAlt SumArity -- ^ @{ (\#|e|\#) }@
| CondE Exp Exp Exp -- ^ if文
| LetE Dec Exp -- ^ @{ let { x=e1; y=e2 } in e3 }@ | CaseE Exp Match -- ^ @{ case e of m1; m2 }@ | DoE Stmt -- ^ @{ do { p <- e1; e2 } }@ | MDoE Stmt -- ^ @{ mdo { x <- e1 y; y <- e2 x; } }@ | SigE Exp Type -- ^ @{ e :: t }@
| RecConE Name FieldExp -- ^ @{ T { x = y, z = w } }@ | RecUpdE Exp FieldExp -- ^ @{ (f x) { z = w } }@ | StaticE Exp -- ^ @{ static e }@
| UnboundVarE Name -- ^ @{ _x }@
| LabelE String -- ^ @{ #x }@ ( Overloaded label ) | ImplicitParamVarE String -- ^ @{ ?x }@ ( Implicit parameter )
Pat
code:hs
data Pat
= LitP Lit -- ^ @{ 5 or \'c\' }@
| VarP Name -- ^ @{ x }@
| TupP Pat -- ^ @{ (p1,p2) }@ | UnboxedTupP Pat -- ^ @{ (\# p1,p2 \#) }@ | UnboxedSumP Pat SumAlt SumArity -- ^ @{ (\#|p|\#) }@
| ConP Name Pat -- ^ @data T1 = C1 t1 t2; {C1 p1 p1} = e@ | InfixP Pat Name Pat -- ^ @foo ({x :+ y}) = e@
| UInfixP Pat Name Pat -- ^ @foo ({x :+ y}) = e@
| ParensP Pat -- ^ @{(p)}@
| TildeP Pat -- ^ @{ ~p }@
| BangP Pat -- ^ @{ !p }@
| AsP Name Pat -- ^ @{ x \@ p }@
| WildP -- ^ @{ _ }@
| RecP Name FieldPat -- ^ @f (Pt { pointx = x }) = g x@ | SigP Pat Type -- ^ @{ p :: t }@
| ViewP Exp Pat -- ^ @{ e -> p }@
Just